package com.tools.cleanmaster.candysaver;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.text.Html;
import android.widget.RemoteViews;

import com.tools.cleanmaster.CleanConstant;
import com.tools.cleanmaster.ui.activity.ChargingSettingActivity;
import com.tools.cleanmaster.utils.LogHelper;

/**
 * 通知栏带量，Notification
 */
public class CandySaverNotification {
    public static final String TAG = "LockScreenNotification";

    public static final String NOTIFICATION_NAME = "LockScreenNotification";
    public static final int NOTIFICATION_ID = 10001;

    public static void show(Context context) {
        LogHelper.i(TAG, "show 展示通知栏带量");

        NotificationManager notifyManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

        Notification notification = new Notification();
        notification.flags = Notification.FLAG_AUTO_CANCEL;
        notification.icon = com.tools.cleanmaster.R.drawable.toast_icon;
        notification.tickerText = Html.fromHtml(context.getString(com.tools.cleanmaster.R.string.charge_status_content));
        notification.defaults = 0;
        notification.sound = null;
        notification.vibrate = null;
        notification.contentIntent = getContentIntent(context);
        notification.contentView = getContentViews(context);
        notifyManager.notify(NOTIFICATION_NAME, NOTIFICATION_ID, notification);
    }

    private static PendingIntent getContentIntent(Context context) {
        Intent intent = new Intent(context, ChargingSettingActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
        intent.putExtra(CleanConstant.EXTRA_FROM_KEY, CleanConstant.EXTRA_FROM_VALUE_STATUSBAR);

        PendingIntent realIntent = PendingIntent
                .getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
        return realIntent;
    }

    private static RemoteViews getContentViews(Context context) {
        RemoteViews remoteViews = new RemoteViews(context.getPackageName(), com.tools.cleanmaster.R.layout.notification_screen_saver);
        remoteViews.setImageViewResource(com.tools.cleanmaster.R.id.left_icon, com.tools.cleanmaster.R.drawable.ic_scene_lockscreen);
        remoteViews.setImageViewResource(com.tools.cleanmaster.R.id.right_icon, com.tools.cleanmaster.R.drawable.notification_righticon_arrow_selector);
        CharSequence title = context.getResources().getString(com.tools.cleanmaster.R.string.charge_status_title);
        remoteViews.setTextViewText(com.tools.cleanmaster.R.id.title, title);
        remoteViews.setTextColor(com.tools.cleanmaster.R.id.title, Color.parseColor("#0b151d"));
        CharSequence content = Html.fromHtml(context.getString(com.tools.cleanmaster.R.string.charge_status_content));
        remoteViews.setTextViewText(com.tools.cleanmaster.R.id.message, content);
        remoteViews.setTextColor(com.tools.cleanmaster.R.id.message, Color.parseColor("#7c7c7c"));
        return remoteViews;
    }

}
